<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");

if($action=='syshg'){
	$sql="select * from {$db_prefix}users where state=1";
	$result=$db->query($sql);
	while($rs=$db->fetch_array($result)){
		if ($rs['gpprice']>0){
			$curtradenum=floor($rs['gpprice']/$glo_gpcurprice);
			$curtradeprice=$curtradenum*$glo_gpcurprice;
			
			$num=$curtradenum;
			//扣除会员的电子股金额
			$sqlq="update {$db_prefix}users set gpprice=gpprice-'$curtradeprice' where username='".$rs['username']."'";
			$db->query($sqlq);
			//财务记录
			$e_userid=$rs['id'];$e_price=-$curtradeprice;$e_type=1;$e_ptype=4;$e_addtime=$curtime;$e_memo="系统报单币回购";
			hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
			//插入交易记录中
			$sql="insert into {$db_prefix}gp_market(username,num,num1,price,jztime,type,addtime,state) values('".$rs['username']."','".intval($num)."','".intval($num)."','".floatval($glo_gpcurprice)."','".($curtime+24*3600*30)."','1','".$curtime."',0)";
			$db->query($sql);
			
			$curmarketid=$db->insert_id();
			
			$price=$glo_gpcurprice;
			
			require("gptrading.php");
		}
	}
	$db->free_result($result);	
	
	echo "<script>alert('系统回购完毕');location.href='gupiao_syshg.php';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">报单币系统回购</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><form name="form1" method="post" action="?action=syshg" onSubmit="return confirm('确定系统报单币回购吗？')">
          <table width="100%" height="90" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="30" align="center" bgcolor="#FFFFFF" class="left_txt">确定要系统报单币回购吗？一旦执行。系统将自动按照当前的价格自动购买报单币</td>
            </tr>
            <tr>
              <td height="30" align="center" bgcolor="#FFFFFF" class="left_txt"><label>
                <input type="submit" name="Submit" value="确定系统回购">
              </label></td>
            </tr>
          </table>
                </form>
        </td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>